'''
Author: LHY 2601958675@qq.com
Date: 2023-12-06 17:42:06
LastEditors: LHY
LastEditTime: 2023-12-13 11:23:15
Description: 
'''
import requests
from lxml import etree


f = open(f'总.txt',mode='a',encoding='utf-8')

def pyDB(page):
    
    print("sss")
    url = f"https://www.bidutuijian.com/books/zhongshengshouji/00{page}.html"
    print("url=",url)
    res = requests.get(url)
    # print(res.text)
    res.encoding = "utf-8"
    et = etree.HTML(res.text)
    # print(et)
    findList = et.xpath('//div[@class="main1"][2]/p')
    title = et.xpath('//h1[@id="myheader"]/text()')[0]
     
    print("title=",title)
    # print(findList)
    f.write(f'\n\n\n{title} \n\n\n')
    for item in findList:
        find = item.xpath(".//text()")[0]
        print(f"循环======{title}")
        f.write(f'{find}')#csv模块也可以写入
        if not find:
            f.close()
            break
    
for i in range(39):
    
    print(i)
    i+=1
    if i < 10 :
        pyDB(f'0{i}') 
    else :
        pyDB(i)
    


print("完毕")
# f.close()
